package com.hhz.stream.part2;

import com.hhz.lambda.part1.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 练习
 *
 * @Author Rem
 * @Date 2020-02-13
 */

public class TestStream7 {
    List<Employee> employees = Arrays.asList(
            new Employee("张三", 16, 3468.12, Employee.State.BUSY),
            new Employee("李四", 42, 9485.32, Employee.State.FREE),
            new Employee("王五", 24, 5124.4, Employee.State.VOCATION),
            new Employee("赵六", 33, 6381.82, Employee.State.FREE),
            new Employee("田七", 36, 4448.45, Employee.State.BUSY),
            new Employee("方八", 36, 7485.42, Employee.State.VOCATION)
    );

    //给定一个数字列表，如何返回一个由每个数频繁构成的列表
    @Test
    public void test() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        List<Integer> list2 = list.stream()
                .map(a -> a * a)
                .collect(Collectors.toList());
        list2.forEach(System.out::println);
    }


    //用map和reduce方法 数一数流中有多少个Employee
    @Test
    public void test2() {
        Optional<Integer> count = employees.stream()
                .map(a -> 1)
                .reduce(Integer::sum);
        System.out.println(count.get());
    }
}
